<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>


<!DOCTYPE html>
<html>
<head id="MyHead">
    <script src="/resources/Scripts/jquery-1.8.3.min.js" type="text/javascript"></script>
    <script src="/resources/Scripts/jquery.easyui.min-1.3.5.js" type="text/javascript"></script>
        <script src="/resources/Scripts/jquery.datagrid.js" type="text/javascript"></script>
    <script src="/resources/Scripts/JScriptIndex.js" type="text/javascript"></script>
    <link href="/resources/Content/Default.css" rel="stylesheet" type="text/css" />
    <link href="/resources/Content/IndexStyle.css" rel="stylesheet" type="text/css" />

        <link href="/resources/Res/easyui/themes/icon.css" rel="stylesheet" type="text/css" />
        <script src="/resources/Res/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
    <link href="/resources/Res/easyui/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <title>
	
    客户资料

</title>
     <script type="text/javascript" language="javascript">
         $(function () {
             $.extend($.fn.datagrid.methods, {
                 addToolbarItem: function (jq, items) {
                     return jq.each(function () {
                         var dpanel = $(this).datagrid('getPanel');
                         var toolbar = dpanel.children("div.datagrid-toolbar");
                         if (!toolbar.length) {
                             toolbar = $("<div class=\"datagrid-toolbar\"><table cellspacing=\"0\" cellpadding=\"0\"><tr></tr></table></div>").prependTo(dpanel);
                             $(this).datagrid('resize');
                         }
                         var tr = toolbar.find("tr");
                         for (var i = 0; i < items.length; i++) {
                             var btn = items[i];
                             if (btn == "-") {
                                 $("<td><div class=\"datagrid-btn-separator\"></div></td>").appendTo(tr);
                             } else {
                                 var td = $("<td></td>").appendTo(tr);
                                 var b = $("<a href=\"javascript:void(0)\"></a>").appendTo(td);
                                 b[0].onclick = eval(btn.handler || function () { });
                                 b.linkbutton($.extend({}, btn, {
                                     plain: true
                                 }));
                             }
                         }
                     });
                 },
                 removeToolbarItem: function (jq, param) {
                     return jq.each(function () {
                         var dpanel = $(this).datagrid('getPanel');
                         var toolbar = dpanel.children("div.datagrid-toolbar");
                         var cbtn = null;
                         if (typeof param == "number") {
                             cbtn = toolbar.find("td").eq(param).find('span.l-btn-text');
                         } else if (typeof param == "string") {
                             cbtn = toolbar.find("span.l-btn-text:contains('" + param + "')");
                         }
                         if (cbtn && cbtn.length > 0) {
                             cbtn.closest('td').remove();
                             cbtn = null;
                         }
                     });
                 }
             });
         });
    </script>
    
    
                                       <script src="/resources/Res/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
                                         
    <script type="text/javascript" language="javascript">
        $(function () {

            $('#flexigridData').datagrid({
                title: '客户资料', //列表的标题
                iconCls: 'icon-site',
                width: 'auto',
                height: 'auto',
                nowrap: false,
                striped: true,
                collapsible: true,
                url: 'getCustData', //获取数据的url
                sortName: 'custId',
                sortOrder: 'desc',
                idField: 'custId',

                toolbar: [
                                      {
                                          text: '查询',
                                          iconCls: 'icon-search',
                                          handler: function () {
                                              flexiQuery();
                                          }
                                      },
                     {
                        text: '详细',
                        iconCls: 'icon-search',
                        handler: function () {
                            return getView();
                        }
                    }, {
                        text: '创建',
                        iconCls: 'icon-add',
                        handler: function () {
                            return flexiCreate();
                        }
                    },  {
                        text: '删除',
                        iconCls: 'icon-remove',
                        handler: function () {
                            return flexiDelete();
                        }
                    }, {
                        text: '修改',
                        iconCls: 'icon-edit',
                        handler: function () {
                            return flexiModify();
                        }
                    }, {
                        text: '发送短信',
                        iconCls: 'icon-edit',
                        handler: function () {
                            return SendSms();
                        }
                    }],
                columns: [[

                    { field: 'ck', checkbox: true },
                    { field: 'custId',title:'id',width:150,hidden:'true'}
					,{ field: 'custPhone', title: '<label for="custPhone">手机</label>', width: 105 }
					,{ field: 'custName', title:  '<label for="custName">姓名</label>', width: 75 }
					,{ field: 'custSex', title:  '<label for="custSex">性别</label>', width: 75 }
					,{ field: 'custGroup', title:  '<label for="custGroup">组别</label>', width: 75 }
					,{ field: 'custBirth', title:  '<label for="custBirth">生日</label>', width: 75
                    , formatter: function (value, rec) {
                        if (value) {
                            return dateConvert(value);
                        } 
                    } 
}
					,{ field: 'custRemake', title:  '<label for="custRemake">备注</label>', width: 75 }
					,{ field: 'custCreateDate', title:  '<label for="custCreateDate">创建时间</label>', width: 75
                    , formatter: function (value, rec) {
                        if (value) {
                            return dateConvert(value);
                        } 
                    } 
}
					,{ field: 'custCreater', title:  '<label for="custCreater">创建人</label>', width: 75 }
					,{ field: 'custEditDate', title:  '<label for="custEditDate">编辑时间</label>', width: 75
                    , formatter: function (value, rec) {
                        if (value) {
                            return dateConvert(value);
                        } 
                    } 
}
					,{ field: 'custEditor', title:  '<label for="custEditor">编辑人</label>', width: 75 }
                ]],
                pagination: true,
                rownumbers: true

            });

             var parent = window.dialogArguments; //获取父页面
            if (parent == "undefined" || parent == null) {
                //    不是在iframe中打开的
            } else {
                //隐藏所有的按钮和分隔符
                $(".l-btn.l-btn-plain").hide();
                $(".datagrid-btn-separator").hide();
                //添加选择按钮
                $('#flexigridData').datagrid("addToolbarItem", [{ "text": "选择", "iconCls": "icon-ok", handler: function () { flexiSelect(); } }]);
            }
        });

        //“查询”按钮，弹出查询框
        /* function flexiQuery() {

            //将查询条件按照分隔符拼接成字符串
             var search = "";
            $('#divQuery').find(":text,:selected,select,textarea,:hidden,:checked,:password").each(function () {
                search = search + this.id + "&" + this.value + "^";
            }); 
            //执行查询                        
            $('#flexigridData').datagrid('reload', { 
				custPhone : $('#custPhone').val(),
				custName : $('#custName').val(),
				custGroup : $('#custGroup').val(),
				dc_birthdayStart_Time : $('#dc_birthdayStart_Time').val(),
				dc_birthdayEnd_Time : $('#dc_birthdayEnd_Time').val()
            
            });

        }; */

        //“选择”按钮，在其他（与此页面有关联）的页面中，此页面以弹出框的形式出现，选择页面中的数据
        function flexiSelect() {

            var rows = $('#flexigridData').datagrid('getSelections');
            if (rows.length == 0) {
                $.messager.alert('操作提示', '请选择数据!', 'warning');
                return false;
            }

            var arr = [];
            for (var i = 0; i < rows.length; i++) {
                arr.push(rows[i].custId);
            }
            arr.push("^");
            for (var i = 0; i < rows.length; i++) {
                arr.push(rows[i].custPhone);
            }
            //主键列和显示列之间用 ^ 分割   每一项用 , 分割
            if (arr.length > 0) {//一条数据和多于一条
                returnParent(arr.join("&")); //每一项用 & 分割
            }
        }
        //导航到查看详细的按钮
        function getView() {

            var arr = $('#flexigridData').datagrid('getSelections');

            if (arr.length == 1) {
                window.location.href = "custDetails/" + arr[0].custId;
               
            } else {
                $.messager.alert('操作提示', '请选择一条数据!', 'warning');
            }
            return false;
        }
        //导航到创建的按钮
        function flexiCreate() {

            window.location.href = "toCreate";
            return false;
        }
        //导航到修改的按钮
        function flexiModify() {

            var arr = $('#flexigridData').datagrid('getSelections');

            if (arr.length == 1) {
                window.location.href = "toCustEdit/" + arr[0].custId;

            } else {
                $.messager.alert('操作提示', '请选择一条数据!', 'warning');
            }
            return false;

        };
        //删除的按钮
        function flexiDelete() {

            var rows = $('#flexigridData').datagrid('getSelections');
            if (rows.length == 0) {
                $.messager.alert('操作提示', '请选择数据!', 'warning');
                return false;
            }

            var arr = [];
            for (var i = 0; i < rows.length; i++) {
                arr.push(rows[i].custId);
            }

            $.messager.confirm('操作提示', "确认删除这 " + arr.length + " 项吗？", function (r) {
                if (r) {
                    $.post("deleteCust", { query: arr.join(",") }, function (res) {
                        if (res == "OK") {
                           //移除删除的数据

                            $.messager.alert('操作提示', '删除成功!', 'info');
                            $("#flexigridData").datagrid("reload");
                            $("#flexigridData").datagrid("clearSelections");
                        }
                        else {
                            if (res == "") {
                                $.messager.alert('操作提示', '删除失败!请查看该数据与其他模块下的信息的关联，或联系管理员。', 'info');
                            }
                            else {
                               $.messager.alert('操作提示', res, 'info');
                            }
                        }
                    });
                }
            });

        };

        //“查询”按钮，弹出查询框
        function flexiQuery() {
            $('#divQuery').dialog({
                buttons: [{
                    text: '查询',
                    iconCls: 'icon-ok',
                    handler: function () {
                        //将查询条件按照分隔符拼接成字符串
                        var search = "";
                        $('#divQuery').find(":text,:selected,select,textarea,:hidden,:checked,:password").each(function () {
                            search = search + this.id + "&" + this.value + "^";
                        });
                        //执行查询                        
                        $('#flexigridData').datagrid('reload', { 
                        	custPhone : $('#custPhone').val(),
            				custName : $('#custName').val(),
            				custGroup : $('#custGroup').val(),
            				dc_birthdayStart_Time : $('#dc_birthdayStart_Time').val(),
            				dc_birthdayEnd_Time : $('#dc_birthdayEnd_Time').val()
                        });
                    }
                },
                     {
                         text: '取消',
                         iconCls: 'icon-cancel',
                         handler: function () {
                             $('#divQuery').dialog("close");
                         }
                     }]
            });
            $('#divQuery').dialog("open");
        };
    </script>

    <script type="text/javascript" language="javascript">
        $(function () {

            $('#querenfasong').datagrid({
                width: '404',
                height: '231',
                nowrap: false,
                striped: true,
                collapsible: true,
                url: 'getCustSendMsg', //获取数据的url
                //queryParams: { search: '1=2^' },
                sortName: 'custId',
                sortOrder: 'asc',
                idField: 'custId',
                toolbar: [

                   {
                       text: '删除',
                       iconCls: 'icon-ok',
                       handler: function () {
                           return fasongDelete();
                       }
                   }],
                columns: [[
					{ field: 'custPhone', title: '<label for="custPhone">手机</label>', width: 105 }
					, { field: 'custName', title: '<label for="custName">姓名</label>', width: 80 }
					, { field: 'custSex', title: '<label for="custSex">性别</label>', width: 50 }
					, { field: 'custGroup', title: '<label for="custGroup">组别</label>', width: 50 }
					, { field: 'custBirth', title: '<label for="custBirth">生日</label>', width: 80
                    , formatter: function (value, rec) {
                        if (value) {
                            return dateConvert(value);
                        }
                    }
					}
                ]],
                pagination: false,
                rownumbers: false
            });

        });


        function SendSms() {

            var obj = $('#flexigridData');
            var rows = obj.datagrid('getSelections');
            if (rows.length == 0) {
                $.messager.alert('操作提示', '请选择数据!', 'warning');
                return false;
            }

            var arr = [];
            var search = "";
            for (var i = 0; i < rows.length; i++) {
                arr.push(rows[i].custId);

            }
            
            //search = arr.join(",");
            //获取短信编号
            $.post("GetSmsCode", function (res) {
                //alert(res);

                $("#msgCode").html(res);
            });
            //获取短信编号

            //alert(search);
            //将待发送列表装载到确认发送列表
            //执行查询
            $('#querenfasong').datagrid('reload', { search: arr.join(",") });
            var $win;
            $win = $('#test-window');
            $win.window('open');
        }

        //删除的按钮
        function fasongDelete() {
            var rows = $('#querenfasong').datagrid('getSelections');
            var arr = [];
            if (rows.length == 0) {
                $.messager.alert('操作提示', '请选择数据!', 'warning');
                return false;
            }
            $.messager.confirm('操作提示', "确认删除这 " + rows.length + " 项吗？", function (r) {

                for (var i = rows.length - 1; i >= 0; i--) {
                    var index = $('#querenfasong').datagrid('getRowIndex', rows[i]); //获取某行的行号
                    $('#querenfasong').datagrid('deleteRow', index); //通过行号移除该行
                }

            });

        }
        //取消发送 关闭
        function cannelSend() {
            $('#test-window').window('close', true);
        }
        //确认发送短信
       function SendTrue() {
            var title = $("#msgTitle").val();
            var SsContent = $("#msgContent").val();
            if (title == "") {
                $.messager.alert('操作提示', '请输入短信标题!', 'warning');
                return false;
            }
            if (SsContent == "") {
                $.messager.alert('操作提示', '请输入短信内容!', 'warning');
                return false;
            }
            $.messager.confirm('操作提示', "确认要发送吗？", function (r) {
                var rows = $('#querenfasong').datagrid('getRows');
                var arr = [], sno = [];
                var pkid = "isCustomer"; //区分是学生表还是客户表
                for (var i = 0; i < rows.length; i++) {
                    arr.push(rows[i].custPhone); //学员手机
                    sno.push(rows[i].custName); //学员编号
                    //pkid.push(rows[i].custId); //考试报名ID
                }
               
                //alert(pkid[0]);
                if (r) {
                    $.post("SengSmsAndSmsAdd", { query: arr.join(","), sno: sno.join(","), pkids: pkid, title: title, SsContent: SsContent }, function (res) {
                        //alert(res);
                        $.messager.alert('操作提示', res, 'warning');
                        $("#msgTitle").val("");
                        $("#msgContent").val("");
                        cannelSend();
                    });
                }
            });

        }
        //确认发送短信
         </script>  

      <base target = "_self">
</head>
<body class="easyui-layout" style="padding:3px;">
    <table id="flexigridData" fit="true">
    </table>
    
    <div id="divQuery" title="查询列表" class="easyui-dialog" closed="true" modal="false"
        iconcls="icon-search">
         
            <div class="input">
                <div class="editor-label-search">
                    <label for="custPhone">手机</label>：
                </div>
                <div class="editor-field-search">
                    <input type='text' id='custPhone'/>
                </div>
            </div> 
            <div class="input">
                <div class="editor-label-search">
                    <label for="custName">姓名</label>：
                </div>
                <div class="editor-field-search">
                    <input type='text' id='custName'/>
                </div>
            </div> 
             <div class="input">
                <div class="editor-label-search">
                    <label for="custGroup">组别</label>：
                </div>
                <div class="editor-field-search">
                    <select id="custGroup" name="custGroup"><option value="">请选择</option>
<option value="客户">客户</option>
</select>  
                </div>
            </div> 
            <div class='left02'>
                <div class="editor-label-search">
                    <label for="custBirth">生日</label>：
                </div>
                <div class="editor-field-to" style="width:280px;">
                    <input type="text" id="dc_birthdayStart_Time" onclick="WdatePicker({maxDate:'#F{$dp.$D(\'dc_birthdayEnd_Time\');}'})"  />
                    到
                    <input type="text" id="dc_birthdayEnd_Time" onclick="WdatePicker({minDate:'#F{$dp.$D(\'dc_birthdayStart_Time\');}'})" />
                </div>
            </div>
                  
                                   
    </div>


     <!--发送短信-->
     <link href="/resources/Content/StyleSheet.css" rel="stylesheet" type="text/css" />
        <div id="test-window" class="easyui-window" title="发送信息" minimizable="false" collapsible="false" closed="true" modal="true" style="width: 600px; height: 520px;">
        <div style="padding: 5px; padding-top:0px; text-align: center;">

                <fieldset style=" width:542px; padding-bottom:10px;">
        <legend>
            <input class="submitcss" type="button" onclick="return SendTrue();" value="确认发送" />
            <input class="submitcss" type="button" onclick="return cannelSend();" value="取消发送" />
        </legend>
        <style type="text/css">
            .editor-label-xx,.textarea-box-xx{ float:left; margin-top:8px;}
            .editor-label-xx{ width:120px; text-align:center;}
            .textarea-box-xx{ width:380px; text-align:left;}
        </style>
        <div class="bigdiv">
            <div class="editor-label-xx">
                <label for="msgCode">短信编号</label>
            </div>
           <div class="textarea-box-xx">
                <b><span id="msgCode"></span></b>
            </div>
            <div class="editor-label-xx">
                <label for="msgTitle">短信标题</label>
            </div>
            <div class="textarea-box-xx">
                <input class="text-box single-line" data-val="true" data-val-length="长度不可超过200" data-val-length-max="200" style="width:400px;" id="msgTitle" name="msgTitle" type="text" value="" />
                <span class="field-validation-valid" data-valmsg-for="msgTitle" data-valmsg-replace="true"></span>
            </div>
            
             <div class="editor-label-xx">
                <label for="msgContect">短信内容</label>
            </div>
            <div class="textarea-box-xx">
                <textarea cols="20" data-val="true" data-val-length="长度不可超过4000" data-val-length-max="4000" id="msgContent" name="msgContent" rows="2" style="width:400px;">
</textarea>
                <span class="field-validation-valid" data-valmsg-for="msgContent" data-valmsg-replace="true"></span>
            </div>
             <div class="editor-label-xx">
                <label for="msgReceiver">接 收 人</label>
            </div>
            <div class="textarea-box-xx">
            <table id="querenfasong"></table>
            </div>
        </div>
    </fieldset>
        </div>
        </div>

        

</body>
</html>
